<?php

namespace App\Models;

use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Illuminate\Support\Facades\Request;
use Laravel\Sanctum\HasApiTokens;
use App\Scopes\IsDelScope;

class PatientModel extends BaseModel {

    protected static function booted()
    {
        parent::booted();
    }

    public function __construct(array $attributes = [])
    {
        parent::__construct($attributes);
        $this->connection = Request::header('Environment') ?: 'oms_prod';
    }

    protected $table = "dtrd_ent_rd_patient";
    protected $primaryKey = "data_id";

    const CREATED_AT = 'create_time';
    const UPDATED_AT = null;

    protected $casts = [
        'create_time' => 'datetime:Y-m-d H:i:s',
    ];

    protected $hidden = ['is_del'];
    protected $appends = ['kingdee_name'];

    protected $fillable = [
        'kingdee_customer_id'
    ];

    public function getKingdeeNameAttribute()
    {
        return "{$this->patients_name}{$this->patients_mobile}";
    }

    public function relation()
    {
        return $this->hasOne(DoctorPatientModel::class, 'patient_id', 'data_id');
    }
}
